<template>
	<w-layout showNavbar navTitle="创建记录" :navTitleColor="publicStyles['--color-t1']" background="url('/static/image/bk.png') no-repeat"
		navBackgroundColor="transparent" :scrollTop="page.scrollTop" :navScrollColor="publicStyles['--color-bk']">
		<template #default>
			<view class="container">
				<view class="px-50">
					<up-tabs
						@change="tabChange"
						:list="tabs.list" 
						:current="tabs.current"
						lineWidth="14"
						lineHeight="14"
						:lineColor="`url('/static/icon/public/top-fill.png') 100% 100%`"
						:activeStyle="{
							color: publicStyles['--color'],
							fontWeight: 'bold',
							transform: 'scale(1.2)'
						}"
						:scrollable="false"
						itemStyle="height: 60px;"
					>
					</up-tabs>
				</view>
				
				<view class="" style="">
					<view @click="$u.route(`/pages/red_envelope/detail?id=`)" style="min-height: 320rpx;position: relative;" class="public-card-6 fc px-5 pb-5 pt-40 mt-40" v-for="(item,index) in state.list" :key="index">
						<view class="fr-ac px-40">
							<image style="width: 112rpx;height: 112rpx;border-radius: 50%;" :src="item.headimg" mode=""></image>
							<view class="ml-20 flex-1">
								<view class="">
									{{item.title}} <text class="op-70 ml-20">共{{item.goods_num}}件</text>
								</view>
								<view class="fr-ac mt-20">
									<image style="width: 24rpx;height: 24rpx;" src="/static/icon/public/people.png" mode="widthFix"></image>
									<view class="ml-5 mr-40">
										{{item.goods_total_price}}
									</view>
									
									<image style="width: 24rpx;height: 24rpx;" src="/static/icon/public/fire.png" mode="widthFix"></image>
									<view class="ml-5">
										{{item.user_num}}
									</view>
								</view>
							</view>
						</view>
						<view class="mt-40 py-20 px-40" style="background: linear-gradient(to right,#1B4B59 0%,#08232F 100%);">
							<scroll-view class="" scroll-x="true" >
								<view class="fr-ac">
									<view class="mr-20" v-for="(item2,index2) in item.goods_info" :key="index2">
										<cut-corner :arrow="2" clipSize="15rpx">
											<image style="width: 80rpx;height: 80rpx;" :src="item2.imgurl" mode="widthFix"></image>
										</cut-corner>
									</view>
								</view>
							</scroll-view>
							<view v-if="tabs.current == 3" class="color fs-24 mt-25">
								驳回原因：{{item.reason}}
							</view>
						</view>
						
					</view>
				</view>
				
			</view>
		</template>
	</w-layout>
</template>

<script setup>
	import {
		ref,
		reactive,
		onMounted,
		computed,
		nextTick
	} from 'vue'
	import {
		storeToRefs
	} from 'pinia'
	import {
		onLoad, onPageScroll,
		onReachBottom
	} from '@dcloudio/uni-app'
	import {
		useAppStore
	} from '@/store/app'
	import {
		useColorStore
	} from '@/store/color'
	import {
		my_room
	} from '@/utils/request/api';
	import {
		useUserStore
	} from '@/store/user'
	const userStore = useUserStore()
	const appStore = useAppStore()
	const colorStore = useColorStore()
	const {
		publicStyles
	} = storeToRefs(colorStore)
	onLoad(async(options) => {
		get_my_room()
	})
	onMounted(() => {
		appStore.loadingHandler(false)
	})
	onPageScroll((e)=>{
		page.scrollTop = e.scrollTop
	})
	onReachBottom(()=>{
		if(state.last_limit == state.limit){
			state.page++
			get_my_room()
		}
	})
	
	const page = reactive({
		scrollTop:0
	})
	
	const tabs = reactive({
		current:0,
		list:[
			{
				id:1,
				name:'待审核',
			},
			{
				id:2,
				name:'进行中',
			},
			{
				id:3,
				name:'已结束',
			},
			{
				id:4,
				name:'未通过',
			},
		]
	})
	function tabChange(e){
		tabs.current = e.index
		console.log(tabs.current)
		initData()
		get_my_room()
	}
	
	const state = reactive({
		list:[],
		page:1,
		limit:15,
		last_limit:15,
		
		keyword:'',
	})
	function initData(){
		state.list = []
		state.page = 1
		state.last_limit = 15
	}
	async function get_my_room(){
		const res = await my_room({
			type: tabs.list[tabs.current].id,
			page: state.page
		})
		state.last_limit = res.room.list.length
		state.list = state.list.concat(res.room.list)
	}
</script>

<style lang="scss">
	.shadow {
		box-shadow: 2rpx 2rpx 12rpx var(--shadow);
	}
	.color{
		color: var(--color);
	}

	.container {
		width: 100%;
		min-height: 100%;
		position: relative;
		overflow: hidden;
		box-sizing: border-box;
		padding: 0 30rpx;
		
	}
</style>